package org.sgsm.dungeon.generator.method;

import org.sgsm.dungeon.generator.ObjectType;

public class MethodPost extends MethodCRUD
{
  public MethodPost()
  {
    super();
  }

  public void generateServiceImpl()
  {
    print(getSignature());
    up();
    print(getObjetOut().getName() + " result = null;");
    print("if( p" + getBean() + " != null)");
    up();
    print("Session session = getSession();");
    print("Transaction tx = session.beginTransaction();");
    print("session.saveOrUpdate(p" + getBean() + ");");
    print("tx.commit();");
    print("session.close();");
    print("session.refresh(p" + getBean() + ");");
    print("result = p" + getBean() + ";");
    down();
    print("return result;");
    down();
  }

  public void generateName(String pPack, String pName)
  {
    _ObjetOut = new ObjectType(pPack, pName + "Type");
    _ObjetIn.add(new ObjectType(pPack, pName + "Type"));
    _ObjetIn.add(new ObjectType(pPack, pName + "ScenarioType"));
    _ObjetIn.add(getContext());
    setMethodName("post" + pName);
  }
}
